package ab.mes.controller;

import ab.mes.entity.Bin;
import ab.mes.service.impl.BinServiceImpl;
import ab.mes.tools.PageParams;
import ab.mes.tools.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/bin")
public class BinController {
    @Autowired
    private BinServiceImpl binService;

    //查询物料库位信息
    @PostMapping("/getBin")
    public Result getBin(){
        Result result=new Result();
        try {
            result = binService.getBin();
        }catch (Exception e){
            result.setErrorMessage("查询物料库位失败！");
            e.printStackTrace();
        }
        return result;
    }

    //查询库位编号物料库位信息
    @PostMapping("/getBinById")
    public Result getBinById(String Id){
        Result result=new Result();
        try {
            result = binService.getBinById(Id);
        }catch (Exception e){
            result.setErrorMessage("查询物料库位失败！");
            e.printStackTrace();
        }
        return result;
    }

    //停启用物料库位
    @PostMapping("/updateById")
    public Result updateById(String Id){
        Result result=new Result();
        try {
            binService.updateStateById(Id);
        }catch (Exception e){
            result.setErrorMessage("更新物料库位状态失败！");
            e.printStackTrace();
        }
        return result;
    }

    //编辑物料库位
    @PostMapping("/updateById2")
    public Result updateById2(@RequestBody Bin bin){
        Result result=new Result();
        try {
            binService.updateById2(bin);
        }catch (Exception e){
            result.setErrorMessage("更新物料库位状态失败！");
            e.printStackTrace();
        }
        return result;
    }

    @PostMapping("/getMaterialBinOut")
    public Result getMaterialBinOut(@RequestBody PageParams pageParams) {
        Result result = new Result();
        try {
            result=binService.getMaterialBinOut(pageParams,"order_no");
        }catch (Exception e) {
            result.setErrorMessage("查询物料出库管理失败！");
            e.printStackTrace();
        }
        return result;
    }
}
